/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package com.googlecode.ivybeans.facade;

import java.io.File;
import org.apache.ivy.core.report.ArtifactDownloadReport;

/**
 *
 * @author lforet
 */
public class ArtifactInfo {

    private ArtifactDownloadReport report;
    
    public ArtifactInfo(ArtifactDownloadReport report) {
        this.report = report;
    }

    public String getName() {
        return report.getName();
    }

    public File getJarFile() {
        return (isJar()) ? report.getLocalFile() : null;
    }
    
    public File getSourceFile() {
        throw new UnsupportedOperationException("TODO");
    }
    
    public String getVersion() {
        return report.getArtifact().getModuleRevisionId().getRevision();
    }

    public String getOrganisation() {
        return report.getArtifact().getModuleRevisionId().getOrganisation();
    }

    public boolean isJar() {
        return "jar".equalsIgnoreCase(report.getArtifact().getType());
    }

    public boolean isJavadoc() {
        return "javadoc".equalsIgnoreCase(report.getArtifact().getType());
    }

    public boolean isSource() {
        return "source".equalsIgnoreCase(report.getArtifact().getType());
    }

    @Override
    public String toString() {
        StringBuffer buffer = new StringBuffer(super.toString()).append("[")
                .append(getName()).append(", ")
                .append(getVersion()).append(", ")
                .append(isJar()).append(", ")
                .append(isJavadoc()).append(", ")
                .append(isSource()).append("]");
        return buffer.toString();
    }

    
    
}
